Let $M$ be a von Neumann algebra acting on a Hilbert space H. A closed and densely defined operator $A$ is said to be affiliated with $M$ if $A$ commutes with every unitary operator $U$ in the commutant of $M$.
It has an equivalent form. Let $A=u|A|$ be its polar decomposition. We say $A$ is affiliated with $M$ if and only if the partial iaometry $u$ and the spectral projections of $|A|$ are in $M$.
How to prove the above statement.
When dealing with unbounded operators one needs to be very careful about domains. I'm not that careful below.
Assume first that $A$ is affiliated with $M$. As $AU=UA$ for every unitary in $M'$, taking adjoints we get that $A^*U=UA^*$ for all $U$ in $M'$. Then $A^*AU=A^*UA=UA^*A$ for all $U$ in $M'$. Using the Spectral Theorem (for instance, X.4.11 in Conway's A Course in Functional Analysis) we get that $f(A^*A)U=Uf(A^*A)$ for all Borel functions $f$. As any C$^*$-algebra is spanned by its unitaries, $f(A^*A)T=Tf(A^*A)$ for all $T\in M'$. So, whenever $f(A^*A)$ is bounded, it will be in $M''=M$. Thus the spectral projections of $|A|$ are in $M$. As for $u$, if $S\in M'$ we have, for any $x$ in the domain of $|A|$, $$ Su|A|x=SAx=ASx=u|A|Sx=uS|A|x. $$ So $Su=uS$ on the range of $|A|$. As $u=0$ on the orthogonal complement of the range of $|A|$, we get that $Su=uS$. Thus $u\in M''=M$.
For the converse, if the spectral projections of $|A|$ are in $M$, then using the Spectral Theorem we get that $|A|U=U|A|$ for any unitary $U\in M'$. Then $UA=Uu|A|=uU|A|=u|A|U=AU$, assuming there are no domain issues.